package com.web.cloud.scala.helper

import java.util.concurrent.{CompletableFuture, Executor}

/**
 * @title: AsyncFunction
 * @projectName webCloudAsync
 * @description: TODO
 * @author chengrui
 * @date 2021/9/19 08:09
 */
object AsyncFunction {

  /**
   * 执行并返回对象
   * @param a
   * @param executor
   * @return
   */
  def doBusiness(a: => Any, executor: Executor): CompletableFuture[Any] = {
    val f: CompletableFuture[Any] = CompletableFuture.supplyAsync(() => {
      a
    }, executor)
    f
  }

  /**
   * 执行不需要返回值
   * @param a
   * @param executor
   * @return
   */
  def doBusinessNullResult(a: => Any, executor: Executor)= {
    CompletableFuture.runAsync(() => {
      a
    }, executor)
  }

}
